package com.ssmdemo.controller;

import com.ssmdemo.aop.bean.LoginUser;
import com.ssmdemo.constant.LoginConstant;
import com.ssmdemo.pojo.User;
import com.ssmdemo.service.UserService;
import com.ssmdemo.util.ResultEntity;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/userContreller")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/toLogin")
    public String toLogin(){
        return "commom/login";
    }

    @RequestMapping("/toIndex")
    public String toIndex(){
        return "commom/index";
    }

    @RequestMapping("/loginContreller")
    @ResponseBody
    public String loginContreller(String username, String password, HttpSession httpSession){

        User user=userService.login(username,password);
        user.setPermissionCode(userService.getPermissionCodeById(user.getId()));
        httpSession.setAttribute(LoginConstant.SUCCESS_USER,user);

        ResultEntity resultEntity=new ResultEntity();
        resultEntity.setSUCCESS("user_success");

        return resultEntity.getSUCCESS();
    }

}
